 //
//  XinWenViewController.swift
//  新闻
//
//  Created by 芮京 on 2018/12/10.
//  Copyright © 2018 芮京. All rights reserved.
//

import UIKit
class XinWenViewController: UIViewController {
    //滚动菜单
    private lazy var pageTitleView: MFPageTitleView = {
        let config = MFPageTitleViewConfig()
        config.titleColor = colorWithRGB(r: 43, g: 43, b: 43)
        config.titleSelectedColor = colorWithRGB(r: 211, g: 0, b: 0)
        config.titleFont = UIFont.systemFont(ofSize: 14, weight: .regular)
        config.indicatorColor = colorWithRGB(r: 211, g: 0, b: 0)
        let pageTitleView = MFPageTitleView(frame: CGRect(x: 0, y: navHeight, width: SCREEN_WIDTH, height: 41), titles: ["头条", "娱乐","体育", "财经", "科技", "跟帖","轻松一刻"], config: config)
        pageTitleView.pageTitleViewDelegate = self
        return pageTitleView
    }()
    
    private lazy var pageContentView: MFPageContentView = {
        var childControllers = [UIViewController]()
        var arr:[BaseViewController] = [ToutiaoViewController(),YuleViewController(),TiyuViewController(),CaijingViewController(),KejiViewController(),GentieViewController(),QingsongViewController()];
        for i in 0..<arr.count {
            childControllers.append(arr[i])
        }
        
        let pageContentViewY = pageTitleView.frame.maxY
        let pageContentView = MFPageContentView(frame: CGRect(x: 0, y: pageContentViewY, width: SCREEN_WIDTH, height: SCREEN_HEIGHT-pageContentViewY), parentVC: self, childVCs: childControllers)
        pageContentView.pageContentViewDelegate = self
        return pageContentView
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        //标题
        self.navigationItem.title = "新闻"
        view.addSubview(pageTitleView)
        view.addSubview(pageContentView)
    }
}
extension XinWenViewController: MFPageTitleViewDelegate, MFPageContentViewDelegate {
    func selectedIndexInPageTitleView(pageTitleView: MFPageTitleView, selectedIndex: Int) {
        self.pageContentView.setPageContentViewCurrentIndex(currentIndex: selectedIndex)
    }
    func pageContentViewScroll(progress: CGFloat, originalIndex: Int, targetIndex: Int) {
        self.pageTitleView.setPageTitleView(progress: progress, originalIndex: originalIndex, targetIndex: targetIndex)
    }
}
